package cn.itsource.ymcc.controller;

import cn.hutool.json.JSONUtil;
import cn.itsource.ymcc.result.JsonResult;
import cn.itsource.ymcc.service.ICommonService;
import cn.itsource.ymcc.vo.SMSRegisterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
public class CommonController {
    @Autowired
    private ICommonService commonService;
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @GetMapping("/getImgCode/{imgKey}")
    public JsonResult getImgCode(@PathVariable("imgKey")String imgKey){
        return commonService.getImgCode(imgKey);
    }

    @PostMapping("/sendSmsCode")
    public JsonResult sendSmsCode(@RequestBody SMSRegisterVO registerVO){
        return commonService.sendSmsCode(registerVO);
    }

    @GetMapping("/createToken/{courseId}")
    public JsonResult createToken(@PathVariable("courseId")String id){
        String token = UUID.randomUUID().toString();
        redisTemplate.opsForValue().set(token,id);
        return JsonResult.success().setData(token);
    }
}
